package com.minibobbo.utilities.spe.effectmodules;

import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Array;
import com.minibobbo.utilities.extrectangle.eRectangle;
import com.minibobbo.utilities.spe.SimplePlatformEngine;
import com.minibobbo.utilities.spe.SpeDynamicObject;
import com.minibobbo.utilities.spe.SpeObject;

public abstract class SpeEffectModule {
	//This location is relative to the spawn pointat an angle of 0,. which is facing right normally.
	public Vector2 loc;
	public Vector2 changeVector;
	protected float duration;
	private boolean affectParent = false;
	public boolean disposeMe = false;
	//Should this Effect affect an object more than once?
	private boolean repeatEffect = false;
	SimplePlatformEngine e;
	SpeDynamicObject parent;
	Array<SpeObject> affectedObjects;
	
	//Rectangle to hold the area of the effect
	public eRectangle area;
	
	String primaryData;
	Array<String> secondaryData;

	
	public void setDuration(float duration) {
		this.duration = duration;
	}

	public void setAffectParent(boolean affectParent) {
		this.affectParent = affectParent;
	}

	public void setRepeatEffect(boolean repeatEffect) {
		this.repeatEffect = repeatEffect;
	}

	public void init(SimplePlatformEngine engine, SpeDynamicObject parent) {
		e = engine;
		this.parent = parent;
		loc = new Vector2();
		changeVector = new Vector2();
		affectedObjects = new Array<SpeObject>();
		area = new eRectangle();
		create(parent);
	}
	
	public void addObjectToAffectedList(SpeDynamicObject obj) {
		affectedObjects.add(obj);
		
	}
	
	public void setEngine(SimplePlatformEngine engine) {
		e = engine;
	}
	
	public void update(float delta) {
		updateLocation();
		duration -= delta;
		if(duration <=0) 
			disposeMe = true;
	}
	
	/**
	 * Creates a new effect and adds it to the board. 
	 * @param parent The parent of the effect.  NEEDS: The duration set.  The hit rectangle created.  The location of the hit rectangle.
	 */
	public abstract void create(SpeDynamicObject parent);

	public abstract void checkHits(Array<SpeObject> array);
		
	public void dispose() {
		affectedObjects.clear();
	}
	
	protected void updateLocation() {
		Vector2 place = new Vector2(loc.x + parent.loc.getCenter().x, loc.y + parent.loc.getCenter().y);
		area.setLeft(place.x);
		area.setBottom(place.y);
	}
}
